package acm.蓝桥21;

import java.util.Scanner;

public class C修改成斐波那契的最少次数 {
	static int maxn = (int) (1e5 + 10);
	static int[] src = new int[maxn];
	static int n;

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		for(int i=1;i<=n;i++) {
			src[i]=sc.nextInt();
		}
		int ans=0;
		for(int i=1;i<1000_0;i++) {
			ans=Math.max(ans, count(i));
		}
		System.out.println(n-ans);
	}
	
	public static int count(int a1) {
		long[] q = new long[3];
		int cur = 0;
		q[cur++] = a1;
		int count = 0;
		count += q[0] != src[1] ? 0 : 1;

		for (int i = 2; i <= n&&i<=30; i++) {
			q[cur] = q[(cur + 2) % 3] + q[(cur + 1) % 3];
			if (q[cur] == src[i]) {
				count++;
			}
			if(q[cur]>1e6) {
				return count;
			}
			cur = (cur + 1) % 3;
		}
		return count;
	}
}
